﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Billing.Dtos;
using Billing.Windows;
using Billing.Utilities;

namespace Billing.Controls
{
    public partial class OrderItemControl : UserControl
    {
        public OrderItemControl()
        {
            InitializeComponent();
        }

        private void UserControl_GotFocus(object sender, RoutedEventArgs e)
        {
            //txtTrip1Qty.Focus();
        }

        private void txtTripQty_GotFocus(object sender, RoutedEventArgs e)
        {
            (sender as TextBox).Background = Brushes.White;
            (sender as TextBox).Foreground = Brushes.Black;
            (sender as TextBox).SelectAll();
        }

        private void txtTripQty_LostFocus(object sender, RoutedEventArgs e)
        {
            (sender as TextBox).Background = Brushes.Transparent;
            (sender as TextBox).Foreground = Brushes.White;

            double temp = 0d;
            if (!(double.TryParse((sender as TextBox).Text, out temp)))
            {
                (sender as TextBox).Text = "0";
                (sender as TextBox).SelectAll();
            }
        }

        private void txtTrip1Qty_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Right)
            {
                txtTrip2Qty.Focus();
                txtTrip2Qty.SelectAll();
            }
            //else
            //{
            //    double temp = 0d;
            //    if (!(double.TryParse(txtTrip1Qty.Text, out temp)))
            //    {
            //        txtTrip1Qty.Text = "0";
            //        txtTrip1Qty.SelectAll();
            //    }
            //}
        }

        private void txtTrip2Qty_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Left)
            {
                txtTrip1Qty.Focus();
                txtTrip1Qty.SelectAll();
            }
            else if (e.Key == Key.Right)
            {
                txtTrip3Qty.Focus();
                txtTrip3Qty.SelectAll();
            }
            //else
            //{
            //    double temp = 0d;
            //    if (!(double.TryParse(txtTrip2Qty.Text, out temp)))
            //    {
            //        txtTrip2Qty.Text = "0";
            //        txtTrip2Qty.SelectAll();
            //    }
            //}
        }

        private void txtTrip3Qty_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Left)
            {
                txtTrip2Qty.Focus();
                txtTrip2Qty.SelectAll();
            }
            else if (e.Key == Key.Right)
            {
                txtTrip4Qty.Focus();
                txtTrip4Qty.SelectAll();
            }
            //else
            //{
            //    double temp = 0d;
            //    if (!(double.TryParse(txtTrip3Qty.Text, out temp)))
            //    {
            //        txtTrip3Qty.Text = "0";
            //        txtTrip3Qty.SelectAll();
            //    }
            //}
        }

        private void txtTrip4Qty_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Left)
            {
                txtTrip3Qty.Focus();
                txtTrip3Qty.SelectAll();
            }
            //else
            //{
            //    double temp = 0d;
            //    if (!(double.TryParse(txtTrip4Qty.Text, out temp)))
            //    {
            //        txtTrip4Qty.Text = "0";
            //        txtTrip4Qty.SelectAll();
            //    }
            //}
        }

        private void UserControl_LostFocus(object sender, RoutedEventArgs e)
        {
            txtTrip1Qty.Background = Brushes.Transparent;
            txtTrip2Qty.Background = Brushes.Transparent;
            txtTrip3Qty.Background = Brushes.Transparent;
            txtTrip4Qty.Background = Brushes.Transparent;

            txtTrip1Qty.Foreground = Brushes.White;
            txtTrip2Qty.Foreground = Brushes.White;
            txtTrip3Qty.Foreground = Brushes.White;
            txtTrip4Qty.Foreground = Brushes.White;
        }
    }
}
